package com.zzyl.controller.customer;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.ReservationDto;
import com.zzyl.service.ReservationService;
import com.zzyl.vo.ReservationCountVo;
import com.zzyl.vo.ReservationVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @className: CustomerReservationController
 * @description:
 * @author: InnovatorX
 * @date: 2024/5/30 11:19
 * @Version: 1.0
 */
@RestController
@RequestMapping("/customer/reservation")
public class CustomerReservationController extends ResponseResult<ReservationVo> {
    @Autowired
    private ReservationService reservationService;

    /**
     * 查询小程序用户
     * 查询取消预约数量
     * @return
     */
    @GetMapping("/cancelled-count")
    public ResponseResult<ReservationVo> cancelledCount() {
        Long cancelledCount = reservationService.getCancelledCount();
        return success(cancelledCount);
    }

    /**
     * 查询每个时间段剩余预约次数
     * @param time
     * @return
     */
    @GetMapping("/countByTime")
    public ResponseResult<List<ReservationCountVo>> countByTime(@RequestParam(value = "time", required = false) Long time){
        List<ReservationCountVo> VoList = reservationService.countByTime(time);
        return success(VoList);
    }

    /**
     * 新增预约
     *
     * @param dto
     * @return
     */
    @PostMapping
    public ResponseResult<ReservationVo> addReservation(@RequestBody ReservationDto dto) {
        reservationService.addReservation(dto);
        return success();
    }

    /**
     * 分页查询预定
     *
     * @return
     */
    @GetMapping("/page")
    public ResponseResult<ReservationVo> findAllReservationsByPages(
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(value = "status", required = false) String status
    ) {
        PageResponse<ReservationVo> pageResponse = reservationService.findAllReservationsByPages(pageNum, pageSize, status);
        return success(pageResponse);
    }

    /**
     * 取消预约
     * @param id
     * @return
     */
    @PutMapping("/{id}/cancel")
    public ResponseResult<ReservationVo> cancelReservation(@PathVariable("id") Long id) {
        reservationService.cancelReservationById(id);
        return success();
    }
}
